﻿using DeepZoomPivotConstructor.PivotLib;
using DeepZoomPivotConstructor.VisualLib;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Drawing;
using System.Linq;

namespace t_PivotLib
{


    /// <summary>
    ///This is a test class for PivotCollectionTest and is intended
    ///to contain all PivotCollectionTest Unit Tests
    ///</summary>
    [TestClass()]
    public class t_PivotCollection
    {
        /// <summary>
        ///A test for PivotCollection Constructor
        ///</summary>
        [TestMethod]
        public void TestCTor()
        {
            PivotCollection target = new PivotCollection();
        }

        [TestMethod]
        public void TestAddImages()
        {
            Visual v = new VisualBitmapImage(1.0, 1.0, 100, Color.Black);
            PivotImage target = new PivotImage(v);
            PivotImage target1 = new PivotImage(v);

            PivotCollection c = new PivotCollection();
            c.Add(target);
            c.Add(target1);

            Assert.AreEqual(2, c.Count(), "Expected 2 items in teh list");
        }

        [TestMethod]
        public void TestAddImagesIEnum()
        {
            Visual v = new VisualBitmapImage(1.0, 1.0, 100, Color.Black);
            PivotImage target = new PivotImage(v);
            PivotImage target1 = new PivotImage(v);

            PivotCollection c = new PivotCollection() { target, target1 };
            Assert.AreEqual(2, c.Count(), "Expected 2 items in teh list");
        }

        [TestMethod]
        [ExpectedException(typeof(System.Collections.Generic.KeyNotFoundException))]
        public void TestFacetCatagoryEmptyAccess()
        {
            Visual v = new VisualBitmapImage(1.0, 1.0, 100, Color.Black);
            PivotImage target = new PivotImage(v);
            PivotCollection c = new PivotCollection() { target };

            var dude = c.FacetCatagories["name"];
        }

        [TestMethod]
        public void TestFacetCatagoryAddedFirst()
        {
            PivotCollection c = new PivotCollection();
            c.AddCategory("name");
            var dude = c.FacetCatagories["name"];
            dude.IsFilterVisible = false;

            Visual v = new VisualBitmapImage(1.0, 1.0, 100, Color.Black);
            PivotImage target = new PivotImage(v) { { "name", "fork" } };
            c.Add(target);

            dude = c.FacetCatagories["name"];
            Assert.IsFalse(dude.IsFilterVisible, "Expected filter visible to be false");
        }

        [TestMethod]
        public void TestFacetCatagoryAddedTwice()
        {
            PivotCollection c = new PivotCollection();
            Visual v = new VisualBitmapImage(1.0, 1.0, 100, Color.Black);
            PivotImage target = new PivotImage(v) { { "name", "fork" } };
            c.Add(target);

            c.AddCategory("name");
            var dude = c.FacetCatagories["name"];
            dude.IsFilterVisible = false;


            dude = c.FacetCatagories["name"];
            Assert.IsFalse(dude.IsFilterVisible, "Expected filter visible to be false");
        }


        [TestMethod]
        public void TestFacetCatagoryAddedFirstTrue()
        {
            PivotCollection c = new PivotCollection();
            c.AddCategory("name");
            var dude = c.FacetCatagories["name"];
            dude.IsFilterVisible = true;

            Visual v = new VisualBitmapImage(1.0, 1.0, 100, Color.Black);
            PivotImage target = new PivotImage(v) { { "name", "fork" } };
            c.Add(target);

            dude = c.FacetCatagories["name"];
            Assert.IsTrue(dude.IsFilterVisible, "Expected filter visible to be false");
        }

        [TestMethod]
        public void TestFacetCatagoryCollected()
        {
            Visual v = new VisualBitmapImage(1.0, 1.0, 100, Color.Black);
            PivotImage target = new PivotImage(v) { { "name", "fork" }, { "dude", "outthere" } };
            PivotCollection c = new PivotCollection() { target };

            c.FacetCatagories["name"].IsWordWheelVisible = false;
            c.FacetCatagories["name"].IsMetaDataVisible = false;
            c.FacetCatagories["name"].IsFilterVisible = false;
            c.FacetCatagories["name"].NumberFormat = "F2";

            Assert.IsTrue(c.FacetCatagories["dude"].IsWordWheelVisible, "the wheel visible is false!");
            Assert.IsTrue(c.FacetCatagories["dude"].IsMetaDataVisible, "the wheel visible is false!");
            Assert.IsTrue(c.FacetCatagories["dude"].IsFilterVisible, "the wheel visible is false!");
            Assert.AreEqual("", c.FacetCatagories["dude"].NumberFormat, "Number format");
        }
    }
}
